<?php

namespace app\index\controller;

use app\common\model\ArticleModel;


class Article extends Base
{
	/**
	 * 文章列表
	 * @Author binx
	 * @Date   2021-12-21
	 * @return [type]     [description]
	 */
	public function index()
	{
		$page = input('get.page', 1, 'intval');
		$limit = 10;
		$ArticleModel = new ArticleModel();
		$pageList = $ArticleModel->getPageList([
			['status', '=', 1],
			['is_publish', '=', 1]
		], $page, $limit);
		if ($pageList['total'] > 0) {
			$category_list = ArticleModel::$category_list;
			$oss_upload_config = config('LOCAL_CONFIG');
			foreach ($pageList['data'] as &$v) {
				$v['category_zh'] = $category_list[$v['category']];
				$v['img'] = !empty($v['file_path']) ? $oss_upload_config['url'] . $v['file_path'] : '';
			}
		}

		// dump($pageList['page']);die;
		$this->assign([
			'title' => '文章列表',
			'list' => $pageList['data'],
			'page' => $pageList['page'],
		]);

		return $this->fetch('index');
	}

	/**
	 * 文章详情
	 * @Author binx
	 * @Date   2021-12-21
	 * @return [type]     [description]
	 */
	public function detail()
	{
		$id = input('param.id', 0, 'intval');

		$ArticleModel = new ArticleModel();
		$article = $ArticleModel->getInfo([
			['status', '=', 1],
			['is_publish', '=', 1],
			['id', '=', $id]
		]);

		if (!empty($article)) {
			$article['hits'] += 1;
			$ArticleModel->where(['id'=>$id])->setInc('hits',1);
		}

		$this->assign([
			'title' => $article['title'],
			'article' => $article,
			'url' => config('app_host').'index/article/detail/id/'.$id.'.html',
		]);

		return $this->fetch('detail');
	}
}